package TCP.test4;

import java.io.*;
import java.net.Socket;

public class SeverThread implements Runnable {
    private Socket s;
    public SeverThread(Socket s) {
        this.s=s;
    }

    @Override
    public void run() {
        //接收数据写到文本文件
        try {
            BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
            BufferedWriter bw = new BufferedWriter(new FileWriter("copy.java"));

            String line;
            while ((line=br.readLine())!=null){
                bw.write(line);
                bw.newLine();
                bw.flush();
            }

            //给出反馈
            BufferedWriter bw1=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
            bw1.write("文件上传成功");
            bw1.newLine();
            bw1.flush();

            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
